import React,{Suspense} from 'react';
import {HashRouter as Router,Route,Switch,Redirect} from "react-router-dom"
import { Layout, Menu, Breadcrumb } from 'antd';
import {
  DesktopOutlined,
  PieChartOutlined,
  FileOutlined,
  TeamOutlined,
  UserOutlined,
} from '@ant-design/icons';

const Home=React.lazy(()=>import("./pages/Home"))
const Login=React.lazy(()=>import("./pages/Login"))
const Table=React.lazy(()=>import("./pages/Table"))
const Registered=React.lazy(()=>import("./pages/Registered"))

const { Header, Content, Footer, Sider } = Layout;
const { SubMenu } = Menu;

class SiderDemo extends React.Component {
  state = {
    collapsed: false,
  };

  onCollapse = (collapsed:any) => {
    console.log(collapsed);
    this.setState({ collapsed });
  };

  render() {
    const { collapsed } = this.state;
    return (
      <Layout style={{ minHeight: '100vh' }}>
        <Sider collapsible collapsed={collapsed} onCollapse={this.onCollapse}>
          <div className="logo" />
          <Menu theme="dark" defaultSelectedKeys={['1']} mode="inline">
            <Menu.Item key="1" icon={<PieChartOutlined />}>
              <a href='#/login'>登录</a>
            </Menu.Item>
            <Menu.Item key="2" icon={<FileOutlined />}>
            <a href='#/registered'>注册</a>
            </Menu.Item>
            <Menu.Item key="3" icon={<DesktopOutlined />}>
            <a href='#/home'>首页</a>
            </Menu.Item>
            <Menu.Item key="4" icon={<FileOutlined />}>
            <a href='#/table'>图表</a>
            </Menu.Item>
            
          </Menu>
        </Sider>
        <Layout className="site-layout">
          <Header className="site-layout-background" style={{ padding: 0 }} />
          <Content style={{ margin: '0 16px' }}>
            
            <div className="site-layout-background" style={{ padding: 24, minHeight: 360 }}>
              <Suspense fallback={<div>Loading...</div>}>
              <Router>
                <Switch>
                  <Route path='/' component={Home} exact></Route>
                  <Route path='/home' component={Home}></Route>
                  <Route path='/login' component={Login}></Route>
                  <Route path='/table' component={Table}></Route>
                  <Route path='/registered' component={Registered}></Route>
                </Switch>
              </Router>
              </Suspense>
            </div>
          </Content>
          <Footer style={{ textAlign: 'center' }}>Ant Design ©2018 Created by Ant UED</Footer>
        </Layout>
      </Layout>
    );
  }
}

export default SiderDemo